/*
    fracgen-c : Fractal Generator (using concurrency)
    Copyright (C) 2010 Arpit Sud, Sri Teja Basava & Sidartha Gracias

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import util.*;
import java.awt.image.BufferedImage;

public class ComplexPlane
{
       static final int HEIGHT = 500;     // Height of fractal image in pixels
       static final int WIDTH = 500;	  // Width of fractal iame in pixels

       BufferedImage image;
       double rmin, rmax, imin, imax;
       double ar, ai;
       Complex c;

//Constructor , initializes members to default values 
       public ComplexPlane()
       {
               image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
               rmin = -2.0; rmax = 2.0; imin = -2.0; imax = 2.0;
               ar = 1.0; ai = 1.0;
               c = new Complex();
       }

//return buffered image member of class       
       public BufferedImage getImage()
       {
               return image;
       }

//resets center and axis scales to original values        
       public void reset()
       {
               c = new Complex();
               ar = 1.0; ai = 1.0;

       }

//accepts two integers (x,y) as input  and return complex number corresponding to x+yi      
       public Complex ptoc(int x, int y)
       {
               double mr, mi;
               double rn, in;

               mr = ar/WIDTH*(rmax - rmin);
               mi = -ai/HEIGHT*(imax - imin);
               rn = mr*(x - WIDTH/2) + c.real();
               in = mi*(y - HEIGHT/2) + c.imaginary();

               return new Complex(rn, in);
       }

//Sets center to input x and y values       
       public void setCenter(int x, int y)
       {
               c = ptoc(x, y);
       }

//return center       
       public Complex getCenter()
       {
               return c;
       }

//sets scaling values as specified by input      
       public void setScale(double realAxis, double imaginaryAxis)
       {
               ar = realAxis;
               ai = imaginaryAxis;
       }

//return real axis scaling       
       public double getRealAxisScale()
       {
               return ar;
       }

//return imaginary axis scaling       
       public double getImaginaryAxisScale()
       {
               return ai;
       }
}
